function playEvents()

% diff(events(1,find(events(2,:)==6)))=
%    30.4436   16.2887   27.6458   39.6553   
%    29.2572   33.8664   20.1802
%    17.4869   18.0465   30.3176   28.5990

load eventsNJ59run7_20101103

effectorEvents(2,:) = effectorEvents(2,:)+10;
events = [stimEvents,effectorEvents];
[dummy,sortIdx] = sort(events(1,:));
events=events(:,sortIdx);

% initialize
restingVal=1e-12;
armPos = 5000;
setArmSystem(2); % 1- right arm 0-left arm 2-no arm
setBallSystem(2);
setPosition(armPos);
setDirection(restingVal);

pause(1); % 5 seconds to start
destination=0;
for k=3:size(events,2);
    pause(events(1,k)-events(1,k-1)); % wait until current event onset
    switch events(2,k),
        case 1,
            setArmSystem(2);
            setBallSystem(2);
            setPosition(5000);
            setDirection(restingVal);
            setArmSystem(0);
            setBallSystem(0);
            destination=1;
        case 3,
            setArmSystem(2);
            setBallSystem(2);
            setPosition(5000);
            setDirection(restingVal);
            setArmSystem(1);
            setBallSystem(1);     
            destination=3;
        case 6,
            setDirection(1);
            while getPosition <10000,                
                pause(0.1)
            end
        case 11,
            if destination ==1,
                setDirection(1);
            else
                setDirection(-1);
            end
        case 12,
            setDirection(restingVal);            
        case 13,
            if destination ==3,
                setDirection(1);
            else
                setDirection(-1);
            end
    end
end

setArmSystem(2);
setBallSystem(2);

    